package com.ruicar.afs.cloud.account.common.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.ruicar.afs.cloud.common.modules.contract.enums.VoucherSendStatus;
import com.ruicar.afs.cloud.common.modules.contract.enums.VoucherStatusEnum;
import com.ruicar.afs.cloud.common.modules.dto.mq.voucher.VoucherFlowInfoDto;
import com.ruicar.afs.cloud.common.modules.enums.BusinessType;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @author infinity
 * @version 1.0
 * @date 2020/6/19 20:10
 */
@Data
@TableName(value ="voucher_flow_info")
public class VoucherFlowInfo{
	private static final long serialVersionUID = 1L;
	@ApiModelProperty("唯一标识")
	@JsonSerialize(
			using = ToStringSerializer.class
	)
	@JSONField(
			serializeUsing = com.alibaba.fastjson.serializer.ToStringSerializer.class
	)
	@TableId(
			value = "id",
			type = IdType.ASSIGN_ID
	)
	private Long id;
	@ApiModelProperty("业务交易流水号")
	@NotBlank(message = "业务交易流水号不能为空")
	private String transNo;

	@ApiModelProperty("埋点编号")
	@NotBlank(message = "埋点编号不能为空")
	private String buriedPointNo;

	/** 合同号 */
	@ApiModelProperty("合同号")
	private String contractNo;

	/** 交易状态 枚举值：待发送，成功，失败 */
	@ApiModelProperty("交易状态 枚举值：未创建，已创建，待发送，成功，失败")
	@NotNull(message = "交易状态不能为空")
	private VoucherStatusEnum status;

	/** 交易状态 枚举值：待发送，成功，失败 */
	@ApiModelProperty("交易状态 枚举值：待发送，成功，失败")
	@NotNull(message = "辅助帐交易状态不能为空")
	private VoucherSendStatus itemStatus;
	/** 品牌 */
	@ApiModelProperty("车辆品牌")
	private String carBrand;
	/** 金融产品 */
	@ApiModelProperty("金融产品")
	private String financialProducts;
	/** 部门 */
	@ApiModelProperty("部门")
	private String department;
	/** 供应商名称 */
	@ApiModelProperty("供应商名称")
	@NotBlank(message = "供应商名称不能为空")
	private String dealerName;
	/** 客户名称 */
	@ApiModelProperty("客户名称")
	private String custName;

	@ApiModelProperty("业务类型 枚举值")
	private BusinessType businessType;
	/** 制单人 */
	@ApiModelProperty("制单人")
	private String creator;

	@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@ApiModelProperty("制单日期")
	private Date preparedDate;

	@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@ApiModelProperty("记账日期")
	private Date keepAccountDate;

	@ApiModelProperty("来源系统")
	private String sourceSystem;

	@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@ApiModelProperty("日切时间")
	private Date dailyCutTime;

	@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@ApiModelProperty("发送日期")
	private Date sendingDate;

	@ApiModelProperty("错误原因")
	private String errMsg;

	@ApiModelProperty("创建者")
	@TableField(
			fill = FieldFill.INSERT
	)
	private String createBy;
	@JsonFormat(
			timezone = "GMT+8",
			pattern = "yyyy-MM-dd HH:mm:ss"
	)
	@DateTimeFormat(
			pattern = "yyyy-MM-dd HH:mm:ss"
	)
	@ApiModelProperty("创建时间")
	@TableField(
			fill = FieldFill.INSERT
	)
	private Date createTime;
	@ApiModelProperty("更新者")
	@TableField(
			fill = FieldFill.UPDATE
	)
	private String updateBy;
	@JsonFormat(
			timezone = "GMT+8",
			pattern = "yyyy-MM-dd HH:mm:ss"
	)
	@DateTimeFormat(
			pattern = "yyyy-MM-dd HH:mm:ss"
	)
	@ApiModelProperty("更新时间")
	@TableField(
			fill = FieldFill.UPDATE
	)
	private Date updateTime;

	public static VoucherFlowInfo convertFromDto(VoucherFlowInfoDto dto) {
		VoucherFlowInfo voucherFlowInfo = new VoucherFlowInfo();
		voucherFlowInfo.setTransNo(dto.getTransNo());
		voucherFlowInfo.setBuriedPointNo(dto.getBuriedPointNo());
		voucherFlowInfo.setBusinessType(dto.getBusinessType());
		voucherFlowInfo.setStatus(VoucherStatusEnum.NOT_CREATED);
		voucherFlowInfo.setItemStatus(VoucherSendStatus.NOT_SEND);
		voucherFlowInfo.setCarBrand(dto.getCarBrand());
		voucherFlowInfo.setCustName(dto.getCustName());
		voucherFlowInfo.setDealerName(dto.getDealerName());
		voucherFlowInfo.setFinancialProducts(dto.getFinancialProducts());
		voucherFlowInfo.setContractNo(dto.getContractNo());
		voucherFlowInfo.setDepartment(dto.getDepartment());
		voucherFlowInfo.setSourceSystem(dto.getSourceSystem());
		voucherFlowInfo.setKeepAccountDate(dto.getKeepAccountDate());
		return voucherFlowInfo;
	}
}
